﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using QxFramework.Core;
public class EnemyBoss : MonoBase
{
    public List<float> ChangeTypeRate;
    public List<string> BossSkills;
    private int CurrentState;
    public static float Range;
    public override void OnEnable()
    {
        base.OnEnable();
        CurrentState = 0;
        Range = GetComponent<CircleCollider2D>().radius + 0.5f;
    }
    public override void Update()
    {
        UseBossSkill();
        base.Update();
    }
    public void UseBossSkill()
    {
        if(monoBase.HPData.HPValue< ((float)monoBase.HPData.HPCeiling) * ChangeTypeRate[CurrentState])
        {
            CurrentState += 1;
            Type t = typeof(EnemyBoss);
            MethodInfo mt = t.GetMethod(BossSkills[CurrentState-1]);
            if (mt == null)
            {
                Debug.LogError("No Function: " + BossSkills[CurrentState-1]);
            }
            mt.Invoke(null, new object[] { monoBase });
        }
    }
    public static void ShootBullet(Mono monoBase)
    {
        CoroutineManager.Instance.StartCoroutine(ExplodeBall(monoBase));
    }
    static IEnumerator ExplodeBall(Mono monoBase)
    {
        for (int Angle = 0; Angle < 360; Angle += 60)
        {
            GameMgr.Get<ISkillManager>().BulletSkillAffect(
                monoBase, "NormalBall", monoBase.Position, Quaternion.Euler(0, 0, Angle) * Vector2.one,0.8f, MonoAttribute.Dark,99);
            yield return new WaitForSeconds(0.1f);
        }
    }
    public static void SpawnFire(Mono monoBase)
    {
        GameMgr.Get<IMissionManager>().InitEnemySpawner(1,"Enemy2Fire",monoBase.Position);
        monoBase.Attr = MonoAttribute.Fire;
    }
    public static void SpawnIce(Mono monoBase)
    {
        GameMgr.Get<IMissionManager>().InitEnemySpawner(1, "Enemy3Ice", monoBase.Position);
        monoBase.Attr = MonoAttribute.Fire;
    }
    public static void SpawnDark(Mono monoBase)
    {
        GameMgr.Get<IMissionManager>().InitEnemySpawner(1, "Enemy4Dark", monoBase.Position);
        monoBase.Attr = MonoAttribute.Ice;
    }
    public static void SpawnFire2(Mono monoBase)
    {
        GameMgr.Get<IMissionManager>().InitEnemySpawner(1, "Enemy4Fire", monoBase.Position);
        monoBase.Attr = MonoAttribute.Fire;
    }
    public static void SpawnDark2(Mono monoBase)
    {
        GameMgr.Get<IMissionManager>().InitEnemySpawner(1, "Enemy5Dark", monoBase.Position);
        monoBase.Attr = MonoAttribute.Ice;
    }
    public static void Final(Mono monoBase)
    {
        monoBase.Attr = MonoAttribute.Dark;
//         SetMagicCircle(MonoAttribute.Dark);
    }
//     private static void SetMagicCircle(MonoAttribute attr,Mono monoBase)
//     {
//         string name = attr.ToString();
//         string[] attributes = { "Fire", "Dark", "Ice", "Shine", "None" };
//         Transform obj = monoBase.gameObject.transform.Find("AttrCircle");
//         for (int i = 0; i < 5; i++)
//         {
//             obj.Find(attributes[i]).gameObject.SetActive(attributes[i] == name);
//         }
//     }
}
